package com.ybxx.hr.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.hr.model.WorkType;
import com.ybxx.hr.service.WorkTypeService;

public class WorkTypeAction extends BaseAction {
	@Resource
	private WorkTypeService workTypeService;
	private WorkType workType;
	private List<WorkType> workTypes;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			workTypeService.remove(workType.getWtid());
		}catch(Exception ex){
			msg="用工方式删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(workType!=null && StringUtils.isNotEmpty(workType.getWtid())){
			workType=workTypeService.get(workType.getWtid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		workTypes=workTypeService.queryPage(workType,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(workType.getWtid())){
			workType.setWtid(UUIDGenerator.getUUID());
		}
		try{
			workTypeService.save(workType);
		}catch(Exception ex){
			msg="岗位信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(workType!=null && StringUtils.isNotEmpty(workType.getWtid())){
			workType=workTypeService.get(workType.getWtid());
		}
		return "load";
	}
	public WorkType getWorkType() {
		return workType;
	}
	public void setWorkType(WorkType workType) {
		this.workType = workType;
	}
	public List<WorkType> getWorkTypes() {
		return workTypes;
	}
	public void setWorkTypes(List<WorkType> workTypes) {
		this.workTypes = workTypes;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
